package cmj.cloudmusic.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cmj.cloudmusic.R;
import cmj.cloudmusic.activity.Fragment_Activity;
import cmj.cloudmusic.activity.MyMuiscActivity;
import cmj.cloudmusic.adapter.MyExpandableListAdapter;
import cmj.cloudmusic.entity.MusicMenuType;
import cmj.cloudmusic.entity.MyMusicMenu;

/**
 * Created by 王虎 on 2016/12/10.
 */
public class MusicFragment extends Fragment implements View.OnClickListener {

    private Context context;
    Fragment_Activity fragment_activity;

    private ExpandableListView listView;
    private MyExpandableListAdapter adapter;
    private LinearLayout ll;

    private Map<String,List<MyMusicMenu>> map;
    private List<MusicMenuType> list;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
        fragment_activity=(Fragment_Activity)context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.music_fragment,null);
        listView= (ExpandableListView) view.findViewById(R.id.listview);
        ll= (LinearLayout) LayoutInflater.from(getActivity()).inflate(R.layout.music_menu, null);
        listView.addHeaderView(ll);
        initData();
        adapter=new MyExpandableListAdapter(context,map,list);
        listView.setAdapter(adapter);

        bindEvent();
        return view;
    }

    public void initData(){
        map=new HashMap<>();
        list=new ArrayList<>();

        ArrayList<MyMusicMenu> list1=new ArrayList<>();
        ArrayList<MyMusicMenu> list2=new ArrayList<>();

        list1.add(new MyMusicMenu(null,"我喜欢的音乐","3"));
        list1.add(new MyMusicMenu(null,"fall out boy","37"));
        list1.add(new MyMusicMenu(null,"睡觉","40"));

        list2.add(new MyMusicMenu(null,"bug","10"));
        list2.add(new MyMusicMenu(null,"bug","10"));
        list2.add(new MyMusicMenu(null,"bug","10"));
        list2.add(new MyMusicMenu(null,"bug","10"));
        map.put(MusicMenuType.CREATE_MENU, list1);
        map.put(MusicMenuType.COLLECT_MENU,list2);
        list.add(new MusicMenuType(MusicMenuType.CREATE_MENU,list1.size()));
        list.add(new MusicMenuType(MusicMenuType.COLLECT_MENU,list2.size()));
    }

    public void bindEvent(){
        ll.findViewById(R.id.bendi).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bendi:
                Intent intent =new Intent(context, MyMuiscActivity.class);
                startActivity(intent);
                break;

        }
    }

}
